package com.techtransteam.techtransteamWeb.controllers;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.springframework.dao.DataAccessException;

import com.techtransteam.techtransteamWeb.dal.entities.Customer;
import com.techtransteam.techtransteamWeb.dal.entities.Role;
import com.techtransteam.techtransteamWeb.services.CustomerService;
import com.techtransteam.techtransteamWeb.services.RoleService;

@ManagedBean(name = "roleMB")
@RequestScoped
public class RoleManagedBean {
	
    private static final long serialVersionUID = 1L;
    private static final String SUCCESS = "success";
    private static final String ERROR   = "error";
    
	private long id;
	private String name;
	private String description;
	
	public List<Role> getRoleList() {
		roleList = new ArrayList<Role>();
		roleList.addAll(roleService.getAllRoles());
		return roleList;
	}

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getSuccess() {
		return SUCCESS;
	}

	public static String getError() {
		return ERROR;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	List<Role> roleList;
	
	@ManagedProperty(value="#{RoleService}")
    RoleService roleService;
	
	public String addRole() {
		try {
			Role role = new Role();
			role.setId(id);
			role.setName(name);
			role.setDescription(description);
			roleService.addRole(role);
			return SUCCESS;
		} catch (DataAccessException e) {
			e.printStackTrace();
		}

		return ERROR;
	}
	
//	public List<Role> getAllRoles(){
//		roleList = new ArrayList<Role>();
//		roleList.addAll(roleService.getAllRoles());
//		return roleList;
//	}
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
}
